package cn.gson.crm.controller.potential;

import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.gson.crm.controller.BaseServlet;
import cn.gson.crm.model.dao.DeptDao;
import cn.gson.crm.model.dao.StudentDao;
import cn.gson.crm.model.entity.Dept;
import cn.gson.crm.model.entity.Student;

/**
 * 显示潜在学员
 */
@WebServlet("/potential")
public class PotentialStu extends BaseServlet{
	private static final long serialVersionUID = 1L;
    private StudentDao stuDao = new StudentDao();
    private DeptDao deptDao = new DeptDao();
	/**
	 * 显示录入学生界面
	 */
	@Override
	protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
		super.get(request, response);
		String name = request.getParameter("userName");
		String p = request.getParameter("page");
		
		if(p == null || p.isEmpty()){
			p = "1";
		}
		//将当前页数进行的类型转换
		Integer page = Integer.parseInt(p);
		
		//获得所有部门
		List<Dept> deptList = deptDao.getDeptList(1);
		
		//带条件的分页显示未分配的学生
		List<Student> stuList = stuDao.getPageStuByStaAndAll("正常", "未分配", page, name);
		
		//获得总页数
		int totalPage = stuDao.getTotalPage("正常", "未分配", name);
		request.setAttribute("stuList", stuList);
		request.setAttribute("deptList", deptList);
		request.setAttribute("totalPage", totalPage);
		request.setAttribute("page", page);
		request.setAttribute("queryString", noPageQueryString(request));
		request.setAttribute("allocation", "未分配");
		getServletPathAndForward(request, "student/student_show.jsp");
	}

}
